﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QModels;

namespace QServices.Services
{
	public class ParameterSettingService: QMainService
	{
		public void SaveParameterSetting(DosingParameter info)
		{
			using var db=CreateDbContext();
			if (string.IsNullOrWhiteSpace(info.ID))
			{
				info.ID = Guid.NewGuid().ToString();
				db.Set<DosingParameter>().Add(info);
			}
            else
            {
				db.Update(info);
            }

			db.SaveChanges();
        }
		public DosingParameter GetDosingParameter(string areaName)
		{
			using var db = CreateDbContext();
			var info = db.Set<DosingParameter>().FirstOrDefault(x => x.Region == areaName);
			return info;
		}
		public List<DosingParameter> GetDosingParameters()
		{
			using var db = CreateDbContext();
			var res=db.Set<DosingParameter>().OrderBy(x=>x.Region).ToList();
			return res;
		}


	}
}
